import os

base_path = os.path.join(os.getcwd().split('StockMonitor')[0] + 'StockMonitor')


# 执行git指令
def git_commend(path, commend):
    if commend == '':
        return 'fail'
    os.chdir(base_path)
    r = os.popen(commend)
    return r.read()


# 提交代码
def git_push(msg):
    if msg == '':
        msg = '提交代码'
    os.chdir(base_path)
    r0 = os.popen('git pull && git add . && git commit -m "后台提交代码"  && git push')
    # print(r0.read())
    return r0.read()


# 更新代码
def git_pull():
    os.chdir(base_path)
    r = os.popen('git pull ')
    return r.read()


# 远端代码同步
def git_reset(branch):
    os.chdir(base_path)
    # r0 = os.popen('git checkout ' + branch)
    r1 = os.popen(
        'git checkout ' + branch + ' && git fetch --all && git reset --hard origin/' + branch + ' && git pull ')
    # r2 = os.popen('git reset --hard origin/' + branch)
    # r3 = os.popen('git pull ')
    return r1.read()


if __name__ == '__main__':
    git_push('')
